{extend name="layout/layout" /}

{block name="content"}
<div class="layui-card">
    <div class="layui-card-header">
        <h3>发送消息</h3>
    </div>
    <div class="layui-card-body">
        <form class="layui-form" action="" lay-filter="message-send-form">
            <div class="layui-form-item">
                <label class="layui-form-label">接收用户</label>
                <div class="layui-input-block">
                    <select name="user_type" lay-verify="required">
                        <option value="">请选择接收用户类型</option>
                        <option value="all">全部用户</option>
                        <option value="vip">VIP用户</option>
                        <option value="normal">普通用户</option>
                        <option value="specific">指定用户</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" id="specific-users" style="display:none;">
                <label class="layui-form-label">用户ID</label>
                <div class="layui-input-block">
                    <textarea name="user_ids" placeholder="请输入用户ID，多个用逗号分隔" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">消息标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" placeholder="请输入消息标题" autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">消息内容</label>
                <div class="layui-input-block">
                    <textarea name="content" placeholder="请输入消息内容" class="layui-textarea" lay-verify="required"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">消息类型</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required">
                        <option value="">请选择消息类型</option>
                        <option value="system">系统消息</option>
                        <option value="notice">通知消息</option>
                        <option value="promotion">推广消息</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发送时间</label>
                <div class="layui-input-block">
                    <input type="text" name="send_time" id="send_time" placeholder="立即发送或选择发送时间" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submit">发送消息</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="script"}
<script>
layui.use(['form', 'laydate'], function(){
    var form = layui.form;
    var laydate = layui.laydate;
    
    // 日期时间选择
    laydate.render({
        elem: '#send_time',
        type: 'datetime'
    });
    
    // 监听用户类型选择
    form.on('select(user_type)', function(data){
        if(data.value === 'specific'){
            $('#specific-users').show();
        } else {
            $('#specific-users').hide();
        }
    });
    
    form.on('submit(submit)', function(data){
        // 发送消息逻辑
        layer.msg('消息发送成功');
        return false;
    });
});
</script>
{/block}